package tpf.designer.pattern.course9.homework;

import org.pentaho.reporting.engine.classic.core.DataFactory;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.DriverConnectionProvider;
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SQLReportDataFactory;
import org.pentaho.reporting.engine.classic.core.wizard.RelationalAutoGeneratorPreProcessor;
import tpf.designer.pattern.course9.AbstractReportGenerator;

import java.util.Map;

public class Sample extends AbstractReportGenerator {

    private static final String QUERY_NAME = "ReportQuery";

    @Override
    public MasterReport getReportDefinition() {
        final MasterReport report = new MasterReport();
        report.setQuery(QUERY_NAME);
        report.addPreProcessor(new RelationalAutoGeneratorPreProcessor());
        return report;
    }

    @Override
    public DataFactory getDataFactory() {
        final DriverConnectionProvider sampleDriverConnectionProvider = new DriverConnectionProvider();
        sampleDriverConnectionProvider.setDriver("net.sourceforge.jtds.jdbc.Driver");
        sampleDriverConnectionProvider.setUrl("jdbc:jtds:sybase://10.200.168.75:7000/symarket60;Charset=gbk");
        sampleDriverConnectionProvider.setProperty("user", "dbo50");
        sampleDriverConnectionProvider.setProperty("password", "password");

        final SQLReportDataFactory dataFactory = new SQLReportDataFactory(sampleDriverConnectionProvider);
        dataFactory.setQuery(QUERY_NAME,
                "SELECT * FROM Tbb_Dept");

        return dataFactory;
    }

    @Override
    public Map<String, Object> getReportParameters() {
        return null;
    }

}
